package com.jing.weibo.service.pb;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.jing.weibo.mapper.pb.PbTypeMapper;
import com.jing.weibo.pojo.pb.PbType;

/**
 * 泡吧分区的Service
 * @author jing.yue
 * @version 2012/09/25 1.0.0
 */
@Component
public class PbTypeService {

	@Autowired
	private PbTypeMapper pbTypeMapper;

	/**
	 * 获取所有泡吧分区列表
	 * @return
	 * @throws Exception
	 */
	public List<PbType> findAllPbType() throws Exception {
		return pbTypeMapper.findAllPbType();
	}

	/**
	 * 添加泡吧分区
	 * @param pbType
	 * @throws Exception
	 */
	public void savePbType(PbType pbType) throws Exception {
		pbTypeMapper.savePbType(pbType);
	}

	/**
	 * 获取分区的详细信息
	 * @return
	 * @throws Exception
	 */
	public List<PbType> findAllDetailPbType() throws Exception {
		List<PbType> pbTypes = pbTypeMapper.findAllPbType();
		int usernum = 0;
		//String stringtime = DateUtil.getTodayYyyyMmDdMaxHhmmss();
		for (PbType pbType : pbTypes) {
			usernum = pbTypeMapper.findByPbTypeIdCountUser(pbType);
			if(pbType.getId().intValue() == 1) {
				//获取没有位置的用户数量
				usernum += pbTypeMapper.findNotPbTypeSeatCountUser();
			}
			pbType.setUsernum(usernum);
		}
		return pbTypes;
	}
}
